<template>
  <div @click="otherClick" :class="{'theme-market': showMarketingBar}">
    <section v-if="examinationInfo!=null" class="c-bg-white">
      <div class="c-maxh427 c-w100 c-text-hidden c-flex-row c-aligni-center">
        <img class="c-w100 c-maxh427" v-lazy="examinationInfo.avatar != '' && examinationInfo.avatar != ' ' && examinationInfo.avatar != null ? examinationInfo.avatar : require('@/assets/examination_defult.png')" alt="" @error="setDefultImg" />
      </div>
      <!-- 营销活动倒计时 -->
      <flash-sales-time-new v-if="showMarketingBar"
        :type="examinationInfo.sales? 'isSale':examinationInfo.isFriendHelper ? 'isFa' : 'isCollage'"
        :price="examinationInfo.sales ? examinationInfo.sales.price : examinationInfo.collage ? examinationInfo.collage.captainPrice : ''"
        :from="examinationInfo.collage && examinationInfo.collage.collageGroupType && examinationInfo.collage.collageGroupType == 2 ? 'activity' : ''"
        :startTime="examinationInfo.sales ? examinationInfo.sales.sales.startTime : examinationInfo.collage ? examinationInfo.collage.startTime : examinationInfo.faStartAt" :endTime="examinationInfo.sales ? examinationInfo.sales.sales.endTime : examinationInfo.collage ? examinationInfo.collage.endTime : examinationInfo.faEndAt" :originalPrice="examinationInfo.price"
        :stock="examinationInfo.sales ? examinationInfo.sales.balance: ''" :isLimit="examinationInfo.sales && examinationInfo.sales.limit == 0 ? false : true" :salesTag="examinationInfo.sales && examinationInfo.sales.sales.tags" :peopleNum="examinationInfo.collage && examinationInfo.collage.peopleNum" @showCoupon="showCoupon = true"
        :optimal="optimal"
        @falshSalesTime="falshSalesTime"
        @finishFlashSales="finishFlashSales"
      >
      </flash-sales-time-new>
      <section class="c-p" v-if="examinationInfo != ''">
        <div class="c-bd-b12-f5 c-mt24">
          <price-bar class="c-ph0 c-mt20" v-if="(examinationInfo.isSaleAlone != -1)&&!examinationInfo.sales && !examinationInfo.collage && !examinationInfo.isFriendHelper && permission == 0"
            :dataInfo="examinationInfo"
            :styleType="2"
          >
          </price-bar>
          <discount-info class="c-mt8" v-if="!distributionId && !isiOS && !permission && examinationInfo.isSaleAlone == 1 && examinationInfo.payType == 2"
            :couponList="couponList"
            :dataInfo="examinationInfo"
            :isMarketing="isMarketing"
            @clickShowCoupon="showCoupon = true"
          >
          </discount-info>
          <vip-entry class="c-ph24 c-mt20"
            :styleType="2"
            :dataInfo="examinationInfo"
            v-if="!permission && !$isWxAppIos() && !isiOS && !isMarketing"
          ></vip-entry>
          <div class="c-ph24 c-mt24">
            <div class="c-fs30 c-fc-xblack c-fw600">{{examinationInfo.name}}</div>
          </div>
          <div class="c-ph24 c-pb20 c-flex-row c-justify-sb c-pt20 c-aligni-center">
            <div class="c-fs22 c-fc-gray c-flex-row c-aligni-center">
              <div class="c-flex-row c-aligni-center">
                <div class="icon iconfont">&#xe792;</div>
                含{{examinationInfo.hasPaper}}套考卷
              </div>
              <div class="c-flex-row c-aligni-center c-ml16">
                <div class="icon iconfont c-fs18 c-mr4">&#xe69c;</div>
                已{{examinationInfo.payType == 2 && !$isWxAppIos() ? '售':'测'}}{{examinationInfo.subscribers}}
              </div>
            </div>
          </div>
          <div class="c-mb10 c-p draw-cer-bg" v-if="isMatch==2 && showCerPop==false">
            <div class="c-ph24 c-hh72 c-flex-row c-aligni-center c-justify-sb">
              <div class="c-fs24 c-fc-white"><span class="icon iconfont c-fs24 c-mr4">&#xe835;</span>恭喜您获得一张结课证书</div>
              <div @click="drawNowCom" class="c-ww140 c-hh48 c-flex-row c-flex-center c-fs20 c-fc-draw c-bg-white c-br36">立即领取</div>
            </div>
          </div>
        </div>
      </section>
      <!-- 非强制表单入口 -->
      <formEntry v-if="isForceFrom"
        relType="12"  :relId="examId"   :dataInfo="examinationInfo"
        classObject="c-fs22" fontSizeClass="c-fs20" iconSizeClass="c-fs14" :topClass="examinationInfo.sales ? 'c-bd-b12-f5':''"
        @goForm="goForm" ></formEntry>
    </section>
    <div class="c-hh76" id="tabhBar">
      <my-small-tabbar class="c-bg-white c-hh76 c-bd-b1-f6 c-ph24" :styleType="2" :class="tabhBarFixed == true ? isiOS ? 'tab-bar-ios' : ($isWxApp() ? 'tabhBar c-wx-top0' : 'tabhBar')  : ''" :tabList="tabList" :tabIndex="typeBar" @changeTab="changeType"></my-small-tabbar>
    </div>
    <div v-show="typeBar==0">
      <div @click="clickDesc" class="c-fs24 c-textAlign-j c-ph24 c-bg-white c-pt28 c-pb20 c-lh48 c-ww-bw c-ww-ba c-contexty-scroll" v-if="examinationInfo && examinationInfo.contact != '' && examinationInfo.contact != null" :class="[cfg.isCopyPicture == 0 ? 'closeBig' : 'aCloseBig', cfg.isCopy == 0 ? 'copyNot' : '']" v-html='examinationInfo.contact'></div>
      <loading-status-tem :noData="examinationInfo&&examinationInfo.contact == ''" :noDataText="'暂无内容'"></loading-status-tem>
      <package-index-com :styleType="2"
        @clickGoAllPackage="showCombo=true"
        :relevantTitles="'包含该测评的课程'"
        :isExam='cfrom.exam' :showAll="true"
        :proType="6" :proId="examId"
        :isHomePage="false"
        :showPackageModal="true"
        :packageList="examinationInfo.combos.filter((item,index) => {return index == 0})"
        v-if="examinationInfo && examinationInfo.combos && examinationInfo.combos.length > 0"></package-index-com>
    </div>
    <div v-show="typeBar==1" class="c-bg-white">
      <div class="c-bg-white c-pl32" v-if="examPaperList.length!=0">
        <div class="c-pv30 c-pr32 c-flex-row c-bd-b1" v-for="(item,index) in examPaperList" :key="index" @click="clickBuy(item.examStatus,item.paperMainId,item.goOnNum,item.hasAns,index,item.enableDayPractice,item.restart)">
          <div>
            <div v-if="examinationInfo && examinationInfo.isBarrier == 1"
              class="c-fs18 c-ph8 c-pv2 theme-bg c-fc-white c-br8 c-mr20">
              {{item.enableStandard==1&&item.isReward == 1 ? '闯关奖励':'闯关式'}}
            </div>
          </div>
          <div class="c-flex-grow1 c-flex-column c-justify-sb">
            <div class="c-lh c-fs28 c-fc-xblack c-text-ellipsis1 c-pt4 c-ww320">{{item.name}}</div>
            <div class="c-flex-row c-aligni-center c-mt14 c-mb14" v-if="item.enableDayPractice==1">
              <span class="c-fs18 c-ph8 c-pv2 c-lh-n theme-bg-10 c-fc-white c-br4 c-mr8 c-p c-vcAlign-middle c-mr10">
                <span class="theme-fc c-fs18">每日一练</span>
                <span class="c-pa prodType-triangle"></span>
              </span>
            </div>
            <div class="c-fs20 c-fc-gray "><span v-if="item.hasHonor==1" class="icon iconfont c-fs20 c-mr12">&#xea1b;</span><span class="c-mr32">共<span class="theme-fc">{{item.hasAns}}</span>题</span><span>{{item.joinNumber}}人参与</span></div>
          </div>
          <div v-if="item.examStatus==1" class="c-fs60 c-textAlign-c icon iconfont c-fc-gray c-hh70 c-lh70">&#xe856;</div>
          <div v-if="examinationInfo && examinationInfo.isBarrier == 1 && index > openKey" class="c-w10 c-textAlign-r icon iconfont c-fs24 c-fc-gray c-hh70 c-lh70">
            &#xe8bc;
          </div>
          <div v-else class="c-w10 c-textAlign-r icon iconfont c-fs20 c-fc-gray c-hh70 c-lh70">
            &#xe60e;
          </div>
        </div>
      </div>
      <loading-status-tem :noData="paperListShow" :noDataText="'暂无考试，请联系管理员'"></loading-status-tem>
    </div>

    <!-- <package-index-com :relevantTitles="'配套课程'" :isExam='cfrom.exam' :showAll="true" :proType="6" :proId="examId" :isHomePage="false" :packageList="packageList" v-if="packageList.length > 0 && companyAuth.enableComboModule == 1"></package-index-com> -->

    <bottom-buy-com v-if="examinationInfo&&! permission"
      :ckFrom="11"
      :isNeedPay="!permission && examinationInfo.payType == 2"
      :showShareMoneyTip="true"
      :deductibleAfterInvition="examinationInfo.commission"
      :showFriendHelper="permission==0 && companyAuth.enableFriendHelper == 1 && examinationInfo.isFriendHelper == true"
      :friendHelperStatus="faStatus"
      :showBuyButton="(permission==0 && (examinationInfo.isFriendHelper == false || companyAuth.enableFriendHelper == 0))
        || (examinationInfo!=null && examinationInfo.sales && examinationInfo.sales.sales.status == 2 && permission == 0)"
      @spreadInvite="clickInviteNow"
      @invitePoster="invitePoster"
      @goHelpDetail="goHelpDetail"
    >
      <!-- isSaleAlone  是否单独售卖：1=是；-1=否
isSaleTogether  是否关联知识套餐售卖 -->
      <div class="c-flex-grow1 c-flex-row c-aligni-center c-justify-end c-w0">
        <div class="c-fs28 c-fc-white c-flex-row c-flex-center theme-bg c-br36 c-hh64 c-flex-grow1 c-w0 c-ml20" v-if="permission==0&& examinationInfo.isSaleTogether == 1 && examinationInfo.isSaleAlone == -1&&packageList.length>0" @click="showPackageList">
          <span class="c-fs28 c-lh">立即购买</span>
        </div>
        <div v-else-if="examinationInfo!=null && examinationInfo.sales && examinationInfo.sales.sales.status == 2 && permission == 0" @click="clickBuy" :class="showMarketingBar ? 'theme-bg-gradient' : 'theme-bg'" class="c-fs28 c-fc-white c-flex-row c-flex-center c-br36 c-flex-grow1 c-w0 c-ml20 c-hh64">
          {{getBuyBtnTitle}}
        </div>
        <template v-else>
          <!-- <div class="c-fs28 c-hh64 c-fc-white c-flex-row c-flex-center theme-bg c-br36 c-w0 c-flex-grow1 c-ml20" v-if="permission==1||permission==3" @click="clickTestNow">
            立即测试
          </div> -->
          <!-- <div class="c-fs28 c-hh64 c-fc-white c-flex-row c-flex-center theme-bg c-br36 c-w0 c-flex-grow1 c-ml20" v-if="permission==2" @click="clickBuy">
            立即测试
          </div> -->
          <div class="c-fs28 c-fc-white c-flex-row c-flex-center theme-bg c-br36 c-hh64 c-flex-grow1 c-w0 c-ml20" v-if="permission==0&& examinationInfo.payType == 2 && (examinationInfo.isFriendHelper == false || companyAuth.enableFriendHelper == 0)" @click="clickBuy">
            <span class="c-fs28 c-lh">立即购买</span>
          </div>
          <!-- 加密 -->
          <div @click="inputPsw" v-if="permission==0 && examinationInfo.payType == 3" class="c-fs28 c-hh64 c-fc-white c-flex-row c-flex-center theme-bg c-br36 c-w0 c-flex-grow1 c-ml20">输入密码</div>
          <div class="c-flex-row c-hh64 c-br32 theme-bd1 c-ml16 c-text-hidden c-w0 c-flex-grow1" v-if="permission==0 &&companyAuth.enableFriendHelper == 1 && examinationInfo.isFriendHelper == true">
            <div class="c-flex-column c-aligni-center theme-fc c-justify-sa c-w100" @click="clickBuy">
              <span class="c-fs22 c-lh">{{'￥' | iosPriceFilter('Live')}}{{calculationPrice}}</span>
              <span class="c-fs20 c-lh">{{getBuyBtnTitle}}</span>
            </div>
            <div class="c-flex-row c-flex-center c-fc-white c-w100" :class="faStatus == 2 ? 'theme-bg-gradient' : 'c-bg-d7'" @click="goHelpDetail()">
              <span class="c-fs26 c-lh">灌溉领取</span>
            </div>
          </div>
        </template>
      </div>
    </bottom-buy-com>
    <!-- 关联弹窗 -->
    <combo-related-list :tittle="'包含该测评的课程'" :minTittle="'购买所属的课程后可参与测评'" :packageList="packageList" @closeCombo="closeCombo" :showCombo="showCombo"></combo-related-list>
    <coupon-list-com
      @closeModal="closeModal"
      @getCouponList="getCouponList"
      :couponIsPage="couponIsPage"
      :couponLoading="couponLoading"
      :couponList="couponList"
      :showCoupon="showCoupon"
      :prodId="Number(examId)"
      :prodType="11"
      :sales="examinationInfo && examinationInfo.sales"
      :isMarketing="isMarketing"
      :dataInfo="examinationInfo"
    >
    </coupon-list-com>
    <comfirm-com :pwTip="''" :showPassword="showPassword" :noticeText="noticeText" :text="'请输入密码进入测试'" :placeholderText="'请输入密码'" @changePsw="changePsw" @closePassword="showPassword = false" @submitPassword="submitPassword"></comfirm-com>
    <promote-income v-if="showProtoIncome && examinationInfo && (isInvitationCard==1 || examinationInfo.showMarketingCard)" :showInvitionCard="isInvitationCard==1" :showMarketingCard="examinationInfo.showMarketingCard" :prodId="examId" :prodType="cfrom.exam" @goInvite="clickInviteNow" @goMarketingPoster="invitePoster"></promote-income>
    <cj-popup v-model="showCerPop" class="c-bg-transparent c-w100">
      <div class="c-w100 c-p">
        <img class="pop-cer" src="https://kposshzcdn.ckjr001.com/admin/material/9_material_admin/image/assets/i/wap/exam/test_pop.png" alt="">
        <p class="c-fc-white c-pa c-w100 c-textAlign-c pop-title-position">恭喜您，获得一张结课证书</p>
        <div class="pop-title-btn c-textAlign-c" @click="drawNowCom">立即领取</div>
        <div class="pop-title-close c-pa c-w100 c-textAlign-c">
          <span class="icon iconfont c-fc-sgray c-fs48" @click="closePop">&#xe84e;</span>
        </div>
      </div>
    </cj-popup>
    <exam-cer-new :bigType="1" ref="examCerNew" :testRes="examinationInfo"></exam-cer-new>
  </div>
</template>

<script>
import PackageIndexCom from "@/components/templates/packageIndexCom.vue";
import loadingStatusTem from "@/components/templates/common/loadingStatusTem.vue";
import { utilJs, wxUtilJs } from "@/utils/common.js"
import defultImg from '@/assets/examination_defult.png'
import couponListCom from "@/components/templates/couponListCom.vue";
import FlashSalesTimeNew from "@/components/templates/flashSalesTimeNew.vue";
import ComfirmCom from "@/components/templates/common/comfirmCom.vue";
import BottomBuyCom from "@/components/templates/common/bottomBuyCom.vue";
import PriceBar from '@/components/templates/common/priceBar.vue';
import PromoteIncome from '@/components/templates/common/promoteIncome.vue';
import { getBindPhoneSetting } from "@/utils/checkUnBindPhone.js";
import DiscountInfo from "@/components/templates/common/discountInfo.vue";
import VipEntry from "@/components/templates/common/vipEntry.vue";
import MySmallTabbar from "@/components/templates/common/MySmallTabbar.vue";
import ComboRelatedList from "@/components/templates/common/comboRelatedList.vue";
import formEntry from "@/components/homePage/form/formEntry.vue"
import examCerNew from "@/components/templates/examination/examCerNew.vue";
let isBuying = false;
const THEME_RGB_MAP = global.THEME_RGB_MAP;
let isClick = false;
export default {
  name: "ExaminationDetail",
  components: {
    examCerNew,
    loadingStatusTem,
    PackageIndexCom,
    couponListCom,
    FlashSalesTimeNew,
    BottomBuyCom,
    PriceBar,
    ComfirmCom,
    PromoteIncome,
    DiscountInfo,
    VipEntry,
    MySmallTabbar,
    ComboRelatedList,
    formEntry
  },
  props: [],
  data() {
    return {
      theme: localStorage.getItem("colorName") ? localStorage.getItem("colorName") : 'mb5_default',
      examId: '',
      is_page: false,
      page: 1,
      limit: 10,
      permission: -1,
      isInvitationCard: -1,
      vipDiscount: '',
      svipDiscount: '',
      examinationInfo: null,
      examPaperList: [],
      tabList: [{
        title: '详情',
        index: 0,
      }, {
        title: '目录',
        index: 1,
      }],
      paperListShow: false,
      showShareMoneyTip: true,
      packageList: [],
      companyAuth: JSON.parse(localStorage.getItem("companyAuth")),
      isLoading: false,
      faStatus: 1,
      showCoupon: false,
      couponList: [],
      couponIsPage: false,
      couponPage: 1,
      couponLoading: false,
      vipType: localStorage.getItem("vipType" + localStorage.getItem("userId")),
      vipFitstItem: localStorage.getItem("vipArr1") ? JSON.parse(localStorage.getItem("vipArr1")) : null,
      svipFitstItem: localStorage.getItem("svipArr1") ? JSON.parse(localStorage.getItem("svipArr1")) : null,
      isShowFormlg:localStorage.getItem("showForm") == 1 ? true : false,
      cfg: JSON.parse(localStorage.getItem("cfg")),
      isSalesBegin: false, // 判断限时购正在进行
      showPassword: false, //显示密码输入
      noticeText: '',
      origin:'', //关联入口来源
      prodId:'', //来源id,
      cfrom: global.ckFrom,
      bindPhoneSetting: null,
      isiOS: false,
      typeBar:0,
      showMarketingBuyBtn:false,
      showCombo:false,
      showProtoIncome: false,
      optimal: null, // 最低价格对象
      isMatch: 1,
      showCer: false,
      showCerPop:false,
      topicType: 0,
      openKey: 0,
    };
  },
  computed: {
    showMarketingBar() {
      return this.examinationInfo &&
        (
          this.examinationInfo.sales ||
          (this.examinationInfo.collage && (this.examinationInfo.collage.status == 2 || this.examinationInfo.collage.status == 1)) ||
          this.examinationInfo.isFriendHelper
        )
    },
    isForceFrom() {
      let isForceFrom = this.permission > 0 && ((this.examinationInfo.collectPage == 3 && this.examinationInfo.isRelForm == true && this.examinationInfo.hasFormLog == false && this.isShowFormlg) || (this.examinationInfo.hasFormLog && this.examinationInfo.enableEdit == 2 && this.isShowFormlg && this.examinationInfo.isRelForm == true));
      return isForceFrom;
    },
    isShowGetCoupon() {
      let isShow = this.examinationInfo && ((this.examinationInfo.sales != null && this.isSalesBegin == false) || this.examinationInfo.collage != null || (this.examinationInfo.collage == null && this.examinationInfo.sales == null)) && this.examinationInfo && !this.examinationInfo.isFriendHelper && this.couponList && this.couponList.length > 0 && this.examinationInfo.price * 1 > 0;
      return isShow;
    },
    showSale() {
      let hasShow = (this.companyAuth.enablePoints == 1 && Number(this.examinationInfo.price) > 0 && this.examinationInfo.deductiblePoints > 0) || (this.permission == 0 && Number(this.examinationInfo.price) > 0 && this.examinationInfo.vipDiscount != 100) || (this.permission == 0 && Number(this.examinationInfo.price) > 0 && this.examinationInfo.svipDiscount != 100)
      return hasShow;
    },
    //是否是营销活动
    isMarketing() {
      let isMarketing = this.examinationInfo &&
      (this.examinationInfo.sales ||
      (this.examinationInfo.collage &&
      (this.examinationInfo.collage.status == 2 || this.examinationInfo.collage.status == 1)) ||
      this.examinationInfo.isFriendHelper)
      return isMarketing
    },
    //单卖&&没有权限&&价格大于0&&（加入形式&&不是好友助力）&&（优惠券||vip svip折扣信息||积分抵扣）&&（是否参与营销）
    showDiscount() {
      let showdiscount = this.examinationInfo.isSaleOnly != 0 && this.permission == 0 && Number(this.examinationInfo.price) > 0 && !this.examinationInfo.isFriendHelper
      return showdiscount
    },
    // 获取按钮专享价名称
    getBuyBtnTitle() {
      if (this.optimal) {
        const agentName = utilJs.getCustNameMap();
        let btnTxt = '立即购买';
        let idDiscount = (this.vipType == 3 || this.vipType > 4) && this.examinationInfo.commonProdInfo && this.examinationInfo.commonProdInfo.agentDiscount < 100
          ? this.examinationInfo.commonProdInfo.agentDiscount
          : (this.vipType == 4 && this.examinationInfo.svipDiscount < 100)
            ? this.examinationInfo.svipDiscount
            : (this.vipType == 2 && this.examinationInfo.vipDiscount < 100)
              ? this.examinationInfo.vipDiscount
              : 100
        let discountPrice = Number(this.examinationInfo.price * idDiscount / 100).toFixed(2);
        btnTxt = discountPrice * 1 != this.examinationInfo.price ? (this.vipType != 1 ? (this.vipType == 2 ? 'VIP专享价' : this.vipType == 4 ? 'SVIP专享价' : agentName[this.vipType] + '专享价') : '立即购买') : '立即购买';
        if (this.examinationInfo.sales && this.optimal.optimalPriceType == 101) {
          btnTxt = '立即购买'
        }
        return btnTxt
      }
      return '立即购买'
    },
    //营销原价计算价格
    calculationPrice() {
      let idDiscount = (this.vipType == 3 || this.vipType > 4) && this.examinationInfo.commonProdInfo && this.examinationInfo.commonProdInfo.agentDiscount < 100
          ? this.examinationInfo.commonProdInfo.agentDiscount
          : (this.vipType == 4 && this.examinationInfo.svipDiscount < 100)
            ? this.examinationInfo.svipDiscount
            : (this.vipType == 2 && this.examinationInfo.vipDiscount < 100)
              ? this.examinationInfo.vipDiscount
              : 100
      let calculationPrice = Number(this.examinationInfo.price * idDiscount / 100).toFixed(2);
      return calculationPrice;
    },
  },
  created() {
    utilJs.appShare(this);
  },
  activated() {
    setDocumentTitle("测评");// eslint-disable-line
    this.showShareMoneyTip = true;
    this.paperListShow = false;
    this.vipDiscount = '';
    this.svipDiscount = '';
    this.page = 1;
    this.permission = -1;
    this.examinationInfo = null;
    this.showProtoIncome = false;
    this.examPaperList = [];
    this.examId = this.$route.query.ExaminationNo;
    this.goodsRoomId = this.$route.query.goodsRoomId || '';
    this.origin = this.$route.query.origin || '';
    this.prodId = this.$route.query.prodId || '';
    this.isiOS = navigator.userAgent.indexOf("IOSLogin") > -1 || navigator.userAgent.indexOf('IOSNewLogin') > -1 || navigator.userAgent.indexOf("IOSNewApp") > -1;
    this.isLoading = false;
    this.packageList = [];
    this.faStatus = 1;
    this.couponPage = 1;
    this.couponIsPage = false;
    this.couponLoading = false;
    this.showCoupon = false;
    this.couponList = [];
    this.optimal = null;
    isBuying = false;
    let $this = this;
    getBindPhoneSetting(global.ckFrom.exam).then(res => {
      this.bindPhoneSetting = res;
    });
    //获取详情信息0删除-1下架
    utilJs.getMethod(global.apiurl + 'exam/topicDetail/' + this.examId + '?isSkeleton=1', function (res) {
      if (res.topicInfo == null || res.topicInfo.isGrounding == 0) {
        $this.$routerGo($this, "replace", {
          path: "/error/emptyPage",
          query: {
            from: "exam",
            info: "很抱歉，该测评已删除"
          }
        });
        return;
      }
      if (res.permission != 1 && res.permission != 3) {
        if (res.topicInfo == null || res.topicInfo.isGrounding != 1) {
          $this.$routerGo($this, "replace", {
            path: "/error/emptyPage",
            query: {
              from: "exam",
              info: "很抱歉，该测评已下架"
            }
          });
          return;
        }
      }
      $this.isMatch = res.topicInfo.isMatch;
      if ($this.isMatch == 2) {
        $this.showCerPop = true;
      }
      $this.topicType = res.topicInfo.topicType;
      $this.companyAuth = JSON.parse(localStorage.getItem("companyAuth"));
      $this.examinationInfo = res.topicInfo;
      // optimalPriceType：1 产品本身价格 2 vip价格 3 svip价格 4 服务商 101 限时购 102 拼团 112 砍价  10 链动会员 20 链动代理商 99 链动复购
      $this.optimal = res.topicInfo.optimal || null;
      console.log($this.examinationInfo.combos)
      $this.wechatShare();

      $this.isInvitationCard = res.topicInfo.isInvitationCard;
      $this.examinationInfo.showMarketingCard = $this.examinationInfo.isFriendHelper || $this.examinationInfo.collage || $this.examinationInfo.sales;
      $this.permission = res.permission; //权限 0：立即购买  1：已经购买过了 立即测试   2：免费
      if ($this.permission != 0) {
        $this.typeBar = 1
      }
      setTimeout(() => {
        $this.showProtoIncome = true;
      }, 100);
      if (res.topicInfo.vipDiscount == 0) {
        $this.vipDiscount = 'VIP免费';
      } else if (res.topicInfo.vipDiscount == 100) {
        $this.vipDiscount = '';
      } else {
        $this.vipDiscount = 'VIP享' + res.topicInfo.vipDiscount / 10 + '折';
      }
      if (res.topicInfo.svipDiscount == 0) {
        $this.svipDiscount = 'SVIP免费';
      } else if (res.topicInfo.svipDiscount == 100) {
        $this.svipDiscount = '';
      } else {
        $this.svipDiscount = 'SVIP享' + res.topicInfo.svipDiscount / 10 + '折';
      }
      // 限时购
      if (res.topicInfo.sales != null && res.topicInfo.sales.status && (res.topicInfo.sales.limit == 0 || res.topicInfo.sales.balance > 0) && $this.companyAuth.enableFlashSalesModule == 1) {
        let nt = (new Date()).getTime();
        let st = utilJs.getTimeByDate(res.topicInfo.sales.sales.startTime);
        let et = utilJs.getTimeByDate(res.topicInfo.sales.sales.endTime);
        if (nt >= st && nt < et && res.topicInfo.sales.sales.status > -1) {
          // $this.ckFrom = global.ckFrom.flashSalesCombo;
          res.topicInfo.sales.sales.status = 2;
        } else if (nt < st && res.topicInfo.sales.sales.status == 1) {
          // $this.ckFrom = global.ckFrom.flashSalesCombo;
          res.topicInfo.sales.sales.status = 1;
          // $this.examinationInfo.sales = null;
        } else if (nt >= et && res.topicInfo.sales.sales.status == 2) {
          res.topicInfo.sales.sales.status = -1;
          $this.examinationInfo.sales = null;
          // $this.cId = -1;
          // $this.ckFrom = global.ckFrom.package;
        } else {
          $this.examinationInfo.sales = null;
          // $this.cId = -1;
          // $this.ckFrom = global.ckFrom.package;
        }
      } else if (res.isFriendHelper) { //友情灌溉
        // let stime = $this.examinationInfo ? utilJs.getTimeByDate($this.examinationInfo.faStartAt) : 0;
        // let etime = $this.examinationInfo ? utilJs.getTimeByDate($this.examinationInfo.faEndAt) : 0;
        // let nowTime = (new Date()).getTime();
        // //faStatus 1未开始,2进行中,-1已结束
        // if (stime > nowTime) {
        //   $this.faStatus = 1;
        // } else if (etime > nowTime) {
        //   $this.faStatus = 2;
        // }
      } else {
        $this.examinationInfo.sales = null;
      }
      if (res.topicInfo.sales && res.topicInfo.sales.sales) {
        $this.isSalesBegin = (res.topicInfo.sales.sales.startTime).replace(/\s+|[-]|[:]/g, "") <= (utilJs.getNowTime()).replace(/\s+|[-]|[:]/g, "") ? true : false;
      }
    });
    this.cloroRGB = THEME_RGB_MAP[this.theme];
    //获取考试列表
    this.getList();
    this.getRelatePackage();
    this.getCouponList();
    window.addEventListener('scroll', this.windowScrollFunction);
  },
  deactivated() {
    this.is_page = false;
    this.showProtoIncome = false;
    window.addEventListener('scroll', this.windowScrollFunction);
  },
  mounted() { },
  methods: {
    drawNowCom() {
      this.$refs.examCerNew.drawNow(this.examinationInfo.topicId, this.examinationInfo.topicId, global.ckFrom.exam)
      this.showCerPop = false
    },
    closePop: function () {
      this.showCerPop = false;
    },
    otherClick() {
      this.showMarketingBuyBtn = false;
    },
    popMarketingBuy() {
      this.showMarketingBuyBtn = true;
    },
    closeCombo() {
      this.showCombo = false;
    },
    showPackageList() {
      this.showCombo = true;
    },
    changeType: function (type, changeDir) {
      if (this.typeBar != type) {
        // this.moveDirection = changeDir;
        this.typeBar = type;
        // this.handleScroll();
        // window.scrollTo(0, 310)
      }
      return false;
    },
    //提交密码
    submitPassword(inputPwd) {
      if (!inputPwd.trim()) {
        this.noticeText = "*密码错误";
        return;
      }
      if (isClick) {
        return;
      }
      isClick = true;
      utilJs.postMethod(global.apiurl + "paper/passwordJoin", {
        password: inputPwd,
        type: 1,
        prodId: this.examId
      }, res => {
        isClick = false;
        if (res.code == 500) {
          this.noticeText = "*密码错误";
        } else if (res.code == 200) {
          this.showPassword = false;
          this.permission = 1
          this.typeBar = 1
          // this.clickTestNow()
        }
      },
        failRes => {
          isClick = false;
        }
      );
    },
    changePsw() {
      this.noticeText = "";
    },
    inputPsw() {
      if (this.bindPhoneSetting && this.bindPhoneSetting.passwordBind) {
        if (utilJs.goBindMobile()) return;
      }
      // 有关联表单，则跳到报名表单处
      if (this.examinationInfo.collectPage != 3 && this.examinationInfo.isRelForm == true && this.examinationInfo.hasFormLog == false && localStorage.getItem("showForm") == 1) {
        this.goForm()
        return;
      }
      this.noticeText = "";
      this.showPassword = true;
    },
    windowScrollFunction: function () {
      let that = this;
      utilJs.handleLoading(function () {
        if (that.is_page == true) {
          that.getList();
        }
      });
    },
    clickDesc(e) {
      if (e.target.tagName == 'IMG' && e.target.src) {
        wxUtilJs.previewImage({
          current: e.target.src, // 当前显示图片的http链接
          urls: [e.target.src] // 需要预览的图片http链接列表
        });
      }
    },
    closeModal() {
      this.showCoupon = false;
    },
    //获取可以领取的优惠券
    getCouponList: function () {
      if (!this.couponLoading) {
        this.couponLoading = true;
        let $this = this;
        utilJs.getMethod(global.apiurl + 'redeemCodes/getCouponsByRedeemType?courseId=' + this.examId + '&redeemType=85&limit=10&page=' + this.couponPage, function (res) {
          $this.couponLoading = false;
          $this.couponList = $this.couponList.concat(res.data);
          $this.couponPage = res.next_page_url ? ($this.couponPage + 1) : $this.couponPage;
          $this.couponIsPage = res.next_page_url ? true : false;
        },
          failRes => {
            $this.couponLoading = false;
          }
        );
      }
    },
    //活动海报
    invitePoster: function () {
      if (this.bindPhoneSetting && this.bindPhoneSetting.shareBind) {
        if (utilJs.goBindMobile()) return;
      }
      let ckFrom = global.ckFrom.exam;//this.ckFrom;
      let type = this.examinationInfo.collage ? 3 : this.examinationInfo.sales ? 2 : 4;
      let cId = this.examinationInfo.isFriendHelper ? this.examinationInfo.faId : this.examinationInfo.collage ? this.examinationInfo.collage.collageId : this.examinationInfo.sales.pId;
      let proId = this.examId;
      this.$routerGo(this, "push", { path: '/homePage/spread/spreadPoster', query: { cId: cId, type: type, ckFrom: ckFrom, proId: proId } });
    },
    // 营销活动倒计时
    falshSalesTime(status) {
      if (this.examinationInfo.sales) {
        this.examinationInfo.sales.sales.status = status
      } else if (this.examinationInfo.collage) {
        this.examinationInfo.collage.status = status
      } else if (this.examinationInfo.isFriendHelper) {
        this.faStatus = status;
      }
    },
    // 营销活动倒计时结束
    finishFlashSales(status) {
      if (this.examinationInfo.sales) {
        this.examinationInfo.sales.sales.status = status
      } else if (this.examinationInfo.collage) {
        this.examinationInfo.collage.status = status
      } else if (this.examinationInfo.isFriendHelper) {
        this.faStatus = status;
      }
      // 活动已结束，清空所有营销活动信息及状态
      if (status == -1) {
        this.examinationInfo.sales = null;
        this.examinationInfo.collage = null;
        this.examinationInfo.isFriendHelper = false;
      }
    },
    goHelpDetail: function () {
      //    this.$routerGo(this, "push", {
      //      path: "/homePage/task/task",
      //      query: {'faId': this.examinationInfo.faId,'refereeId': localStorage.getItem("userId")}
      //    });
      if (this.bindPhoneSetting && this.bindPhoneSetting.helpBind && utilJs.goBindMobile()) {
        return
      }
      if (this.faStatus == 1) {
        this.$showCjToast({
          text: '活动未开始，暂不能助力领取！',
          type: 'warn'
        });
      } else {
        this.$routerGo(this, "push", {
          path: "/homePage/task/task",
          query: { 'faId': this.examinationInfo.faId, 'refereeId': localStorage.getItem("userId") }
        });
      }
    },
    onSearch(e) {
      console.log(e);
    },
    clickExaminationItem(examinationNo) { },
    clickTestNow() {
      if (this.bindPhoneSetting && this.bindPhoneSetting.getBind) {
        if (utilJs.goBindMobile()) return;
      }
      if (this.examinationInfo.collectPage != 3 && this.examinationInfo.isRelForm == true && this.examinationInfo.hasFormLog == false && localStorage.getItem("showForm") == 1) {
        this.goForm();
        return;
      }
      //点击立即测试
      this.$routerGo(this, "push", {
        path: "/homePage/examination/examinationDetailList",
        query: { ExaminationNo: this.examinationInfo.topicId, origin:this.origin, prodId:this.prodId}
      });
    },
    //表单
    goForm() {
      let isGoBack = this.examinationInfo.collectPage == 3 || this.examinationInfo.payType == 3 || this.permission == 1 || this.permission == 3 || this.permission == 2 || (this.isMarketing && !this.examinationInfo.sales) || this.examinationInfo.isSaleOnly == 0 ? 1 : 0;
      let pId = this.examinationInfo.sales ? this.examinationInfo.sales.pId : null;
      let queryT = null;
      if (this.examinationInfo.sales && this.examinationInfo.sales.sales.status == 2) {
        queryT = {cId: -1, extId: this.examinationInfo.topicId, ckFrom: global.ckFrom.flashSalesExam, isFromInvite: 0, pId: pId, isGoBack: isGoBack, type: 1, relType: 12}
      } else {
        queryT = {cId: -1, extId: this.examinationInfo.topicId, ckFrom: global.ckFrom.exam, isFromInvite: 0, isGoBack: isGoBack, type: 1, relType: 12, pId: -1}
      }
      if (this.goodsRoomId) {
        queryT.goodsRoomId = this.goodsRoomId;
      }
      this.$routerGo(this, "push", { path: '/homePage/form', query: queryT });
    },
    goTest: function (examStatus, paperMainId, goOnNum, hasAns, eIndex, enableDayPractice, restart) {
      let $this = this;
//       paperMainId	试卷ID
// prodType	78训练营  61知识套餐
// prodId
    utilJs.getMethod(global.apiurl + 'paper/judgeEntry/' + paperMainId + '?topicId=' + $this.examinationInfo.topicId, function (res) {
      if (res.status == 1) {
        utilJs.postMethod(global.apiurl + "paper/entryRecord", {
          paperMainId: paperMainId,
          prodId: $this.prodId,
          prodType: $this.origin
        }, res => {
          console.log(eIndex, $this.openKey)
        if ($this.examinationInfo.isBarrier == 1 && eIndex > $this.openKey) {
          $this.$showCjToast({
            text: "该考试暂未解锁",
            type: 'warn',
          });
          return;
        }
        if (enableDayPractice == 1 && restart == 1) {
          utilJs.postMethod(global.apiurl + "paperLibrary/createExam", {
            paperMainId: paperMainId,
            topicId:$this.examinationInfo.topicId,
            entryProdType:2,
            prodId:$this.examinationInfo.topicId
          }, res => {
            $this.$routerGo($this, "push", {
              path: "/homePage/examination/examinationAnswer",
              query: { paperMainId: paperMainId, topicId: $this.examinationInfo.topicId, goOnNum: 1 }
            });
          })
        } else {
        // examStatus 0未考试 1已经完成考试 2考试进行一半
          if (examStatus == 0) {
            if (hasAns == 0) {
              $this.$showCjToast({
                text: "该考试暂无题目，请联系管理员",
                type: 'warn',
              });
            } else if ($this.topicType == 1) {
               utilJs.postMethod(global.apiurl + "paperLibrary/createExam", {
                  paperMainId: paperMainId,
                  topicId:$this.examinationInfo.topicId,
                  entryProdType:2,
                  prodId:$this.examinationInfo.topicId
                }, res => {
                  $this.$routerGo($this, "push", {
                    path: "/homePage/examination/examinationAnswer",
                    query: { paperMainId: paperMainId, topicId:$this.examinationInfo.topicId, goOnNum: 1 }
                  });
                })
            } else if ($this.topicType == 2) {
              $this.$routerGo($this, "push", {
                path: "/homePage/examination/quizEntry",
                query: { paperMainId: paperMainId, topicId:$this.examinationInfo.topicId }
              });
            }
          } else if (examStatus == 1) {
            $this.$routerGo($this, "push", {
              path: "/homePage/examination/examinationResult",
              query: { paperMainId: paperMainId, topicId: $this.examinationInfo.topicId }
            });
          } else if (examStatus == 2) {
            if (hasAns == 0) {
              $this.$showCjToast({
                text: "该考试暂无题目，请联系管理员",
                type: 'warn',
              });
            } else {
              if (goOnNum == 1 && $this.topicType == 2) {
                $this.$routerGo($this, "push", {
                  path: "/homePage/examination/quizEntry",
                  query: { paperMainId: paperMainId, topicId:$this.examinationInfo.topicId }
                });
              } else {
                $this.$routerGo($this, "push", {
                  path: "/homePage/examination/examinationAnswer",
                  query: { paperMainId: paperMainId, topicId:$this.examinationInfo.topicId, goOnNum: goOnNum }
                });
              }
            }
          }
        }
        });
      } else {
        $this.$showCjToast({
            text: res.msg + '</br>' + res.showTime,
            type: 'warn'
          });
        }
      })
    },
    clickBuy(examStatus, paperMainId, goOnNum, hasAns, eIndex, enableDayPractice, restart) {
      if (isBuying) {
        return;
      }
      if (this.permission == 0 && this.examinationInfo.payType == 3) {
        this.inputPsw()
        isBuying = false;
        return
      }
      if (this.permission == 0 && this.examinationInfo.isSaleTogether == 1 && this.examinationInfo.isSaleAlone == -1 && this.packageList.length > 0) {
        this.showPackageList()
        isBuying = false;
        return
      }
      if ((this.bindPhoneSetting && this.bindPhoneSetting.getBind && this.permission == 2) || (this.bindPhoneSetting && this.bindPhoneSetting.buyBind && this.permission != 2)) {
        let pathQuery = {};
        if (this.goodsRoomId) {
          pathQuery.goodsRoomId = this.goodsRoomId;
        }
        if (utilJs.goBindMobile(pathQuery)) return;
      }
      if ((this.examinationInfo.collectPage == 1 || (this.examinationInfo.collectPage == 2 && this.permission == 2)) && this.examinationInfo.collectPage != 3 && this.examinationInfo.isRelForm == true && this.examinationInfo.hasFormLog == false && localStorage.getItem("showForm") == 1) {
        this.goForm();
        return;
      }
      isBuying = true;
      let $this = this;
      if (this.permission == 1 || this.permission == 3) {
        isBuying = false;
        $this.goTest(examStatus, paperMainId, goOnNum, hasAns, eIndex, enableDayPractice, restart)
      } else if (this.permission == 2) {
        utilJs.postMethod(global.apiurl + 'exam/freePurchase', { topicId: this.examinationInfo.topicId }, function (res) {
          isBuying = false;
          $this.goTest(examStatus, paperMainId, goOnNum, hasAns, eIndex, enableDayPractice, restart)
          // $this.$routerGo($this, "push", {
          //   path: "/homePage/examination/examinationDetailList",
          //   query: { ExaminationNo: $this.examinationInfo.topicId, origin:$this.origin, prodId:$this.prodId }
          // });
        });
      } else if (this.permission == 0) {
        let queryT = null;
        if (this.examinationInfo.sales && this.examinationInfo.sales.sales.status == 2 && this.optimal && this.optimal.optimalPriceType == 101) {
          let pId = this.examinationInfo.sales.pId;
          queryT = {cId: -1, extId: this.examinationInfo.topicId, ckFrom: global.ckFrom.flashSalesExam, isFromInvite: 0, pId: pId}
        } else {
          queryT = {cId: -1, extId: this.examinationInfo.topicId, ckFrom: global.ckFrom.exam, isFromInvite: 0}
        }
        if (this.goodsRoomId) {
          queryT.goodsRoomId = this.goodsRoomId;
        }
        isBuying = false;
        this.$routerGo(this, "push", {
          path: '/homePage/course/coursePay',
          query: queryT
        });
      }
    },
    clickInviteNow() {
      if (this.bindPhoneSetting && this.bindPhoneSetting.shareBind) {
        if (utilJs.goBindMobile()) return;
      }
      this.$routerGo(this, "push", {
        path: '/homePage/spread/spreadCustom',
        query: { cId: 0, extId: this.examinationInfo.topicId, ckFrom: global.ckFrom.exam, isFromInvite: 0 }
      });
    },
    getList() {
      let $this = this;
      if (this.isLoading == true) {
        return;
      }
      this.isLoading = true;
      utilJs.getMethod(global.apiurl + 'exam/paperInTopic/' + this.examId + '?page=' + this.page + '&limit=' + this.limit, function (res) {
        $this.isLoading = false;
        // $this.examPaperList = res.paper;
        $this.examPaperList = $this.examPaperList.concat(res.paper.data);
        $this.openKey = res.openKey;
        $this.page = res.paper.data && (res.paper.data.length >= $this.limit) ? ($this.page + 1) : $this.page;//res.current_page < res.last_page ? ($this.page + 1) : $this.page;
        $this.is_page = res.paper.data && (res.paper.data.length >= $this.limit) ? true : false;//res.current_page < res.last_page ? true : false;;
        if ($this.examPaperList.length == 0) {
          $this.paperListShow = true;
        }
      }, failRes => {
        $this.isLoading = false;
      });
    },
    getRelatePackage() {
      let $this = this;
      utilJs.getMethod(global.apiurl + "common/saleTogetherList?prodId=" + this.examId + '&prodType=' + global.ckFrom.exam, function (res) {
        $this.packageList = res;
      });
    },
    setDefultImg(e) {
      this.examinationInfo.avatar = defultImg;
    },
    //分享
    wechatShare: function () {
      let title = this.examinationInfo.shareTitle;
      let shareImg = this.examinationInfo.sales ? this.examinationInfo.sales.shareImg : (this.examinationInfo.sharePic ? this.examinationInfo.sharePic : require('@/assets/examination_defult.png'));
      let shareUrl = `${window.location.href.split("#")[0]}#/homePage/examination/examinationDetail?ExaminationNo=${this.examId}&refereeId=${localStorage.getItem("userId")}`;
      let shareDesc = this.examinationInfo.shareDesc;//"共包含"+this.examinationInfo.hasPaper+"套考卷";
      if (this.examinationInfo.sales) {
        title = `【限时抢购】${title}`;
      }
      if (this.companyAuth.enableFriendHelper == 1 && this.examinationInfo.isFriendHelper == true) {
        title = `【快来帮我灌溉吧】${title}`;
      }
      utilJs.wechatConfig(shareUrl, title, shareImg, shareDesc, function () { });
    },
    //手机端分享
    appShare: function () {
      let title = this.examinationInfo.shareTitle;
      let shareImg = this.examinationInfo.sales ? this.examinationInfo.sales.shareImg : (this.examinationInfo.sharePic ? this.examinationInfo.sharePic : require('@/assets/examination_defult.png'));
      let shareUrl = `${window.location.href.split("#")[0]}#/homePage/examination/examinationDetail?ExaminationNo=${this.examId}&refereeId=${localStorage.getItem("userId")}`;
      let shareDesc = this.examinationInfo.shareDesc;//"共包含"+this.examinationInfo.hasPaper+"套考卷";
      if (this.examinationInfo.sales) {
        title = `【限时抢购】${title}`;
      }
      if (this.companyAuth.enableFriendHelper == 1 && this.examinationInfo.isFriendHelper == true) {
        title = `【快来帮我灌溉吧】${title}`;
      }
      utilJs.appShareTrue(title, shareImg, shareUrl, shareDesc);
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->

<style scoped>
.c-pl24 {
  padding-left: 0.6rem;
}
.c-mt-3 {
  margin-top: 3px;
}
.prodType-triangle {
    width: 0;
    height: 0;
    border-width: 0.2rem 0.2rem 0 0.2rem;
    border-style: solid;
    border-color: transparent #fff transparent transparent;
    bottom: 0;
    right: 0;
}
.closeBig >>> p > img,
.closeBig >>> section > img,
.closeBig >>> div > img,
.closeBig >>> img {
  pointer-events: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -o-user-select: none;
  user-select: none;
}
.aCloseBig >>> p > a > img,
.aCloseBig >>> section > a > img,
.aCloseBig >>> div > a > img {
  pointer-events: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -webkit-user-select: none;
  -o-user-select: none;
  user-select: none;
}
.tabhBar {
  width: 100%;
  max-width: 16rem;
  position: fixed;
  top: 1.7rem;
  left: 0;
  right: 0;
  margin: auto;
  background-color: #fff;
  z-index: 900;
}
.tab-bar-ios {
  width: 100%;
  max-width: 16rem;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  margin: auto;
  background-color: #fff;
  z-index: 9999;
}
.examination-item {
  height: 5rem;
  border-radius: 0.25rem;
  background-color: #fff;
  margin-bottom: 0.4rem;
  display: flex;
  display: -webkit-flex;
}
.examination-img {
  width: 2.5rem;
  height: 5rem;
  border-radius: 0.25rem;
  min-width: 2.5rem;
}
.examination-img img {
  width: 100%;
  height: 100%;
}
.draw-cer-bg {
  background: url('../../../assets/i/wap/exam/cer-title-bg.png') no-repeat 0 0;
  background-size: cover;
}
.c-fc-draw {
  color: #fa875d;
}
.pop-cer {
  max-width: inherit;
  width: 480px;
  height: 478px;
  position: relative;
  top: 0;
  left: 50%;
  margin-left: -240px;
}
.pop-title-position {
  font-size: 18px;
  bottom: 218px;
  left: 0;
}
.pop-title-btn {
  font-size: 16px;
  color: #fa6037;
  width: 154px;
  height: 48px;
  line-height: 48px;
  background: rgba(255, 255, 255, 1);
  border-radius: 24px;
  position: absolute;
  bottom: 128px;
  left: 50%;
  margin-left: -78px;
}
.pop-title-close {
  font-size: 32px;
  left: 0;
  bottom: 20px;
}
.prodType-triangle {
    width: 0;
    height: 0;
    border-width: 0.2rem 0.2rem 0 0.2rem;
    border-style: solid;
    border-color: transparent #fff transparent transparent;
    bottom: 0;
    right: 0;
}
</style>


